<template>
<div style="height:600px;overflow-y: auto; ">
  <div class="head_title">基本信息</div>
  <el-form ref="form" :model="form" :rules="rules" style="margin-top: 16px;" size="small" label-width="160px">
	<el-form-item label="所属分行"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.branch" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="所属支行"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.subBranch" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="组织机构代码"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.deptCode" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="客户经理"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.accountManagerName" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="产业结构调整类型"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.industrialAdjustType" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="客户规模(行内)"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.customerScaleIn" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="注册地是否县级以上"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.isRegistOverCounty" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="行业门类分类"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.industryKind" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="行业门类大类"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.industryBigKind" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="行业门类中类"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.industryMidKind" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="行业门类小类"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.industrySmallKind" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="从业人数"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.jobPeopleNum" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="营业收入"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.businessIncome" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="营业总额"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.businessSale" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="台账状态"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.ledgerStatus" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="实际经营地址"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.realBusinessAddr" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="省份"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.province" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="地级市"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.preLevelCity" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="风险等级"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.riskLevel" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="成立日期"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.foundDate" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="是否出口型"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.isExportType" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="是否进口型"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.isImportType" style="width: 370px;"/>
    </el-form-item>
    <el-form-item label="法人代表"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.legalRepresent" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="实际控股人"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.realController" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="客户与我行关联关系"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.custBankRelationship" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="建立信贷关系时间"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.buildCreditTime" style="width: 370px;"/>
    </el-form-item>
	 <el-form-item label="是否龙头企业"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.isLeadingEnterprise" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="是否高新技术企业"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.isHighTechEnterprise" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="是否支持科技创新企业"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.isSupportNewTechEnterprise" style="width: 370px;"/>
    </el-form-item>
	<el-form-item label="是否支持节能减排企业"  prop="deptNum" style="display:inline-block;width:48%;">
         <el-input v-model="form.isSupportEnergySaveEnterprise" style="width: 370px;"/>
    </el-form-item>
    <!-- <el-form-item label="appID" prop="appID" class="two">
      <el-input v-model="form.appID" style="width: 40%"/>
    </el-form-item>
    <el-form-item label="商家账号" prop="sysServiceProviderId"  class="two">
      <el-input v-model="form.sysServiceProviderId" style="width: 40%;"/>
    </el-form-item>
    <el-form-item label="商户私钥" prop="privateKey"  class="two">
      <el-input v-model="form.privateKey" type="password" style="width: 40%;"/>
    </el-form-item>
    <el-form-item label="支付宝公钥" prop="publicKey"  class="two">
      <el-input v-model="form.publicKey" type="password" style="width: 40%;"/>
    </el-form-item>
    <el-form-item label="回调地址" prop="returnUrl"  class="two">
      <el-input v-model="form.returnUrl" style="width: 40%;"/>
    </el-form-item>
    <el-form-item label="异步通知" prop="notifyUrl"  class="two">
      <el-input v-model="form.notifyUrl" style="width: 40%;"/>
    </el-form-item> -->
    <!-- <el-form-item label="">
      <el-button :loading="loading" size="medium" type="primary" @click="doSubmit">保存配置</el-button>
    </el-form-item> -->
  </el-form>
  <div class="head_title space">证件信息</div>
     <el-button
				v-permission="['ADMIN','CUSTCOMBASEINFO_ALL','CUSTCOMBASEINFO_CREATE']"
				class="filter-item"
				size="mini"
				type="primary"
				icon="el-icon-plus"
				@click="add">新增</el-button>
	     <el-button
				v-permission="['ADMIN','CUSTCOMBASEINFO_ALL','CUSTCOMBASEINFO_CREATE']"
				class="filter-item"
				size="mini"
				type="primary"
				@click="effective">生效</el-button>	

		 <el-button
				v-permission="['ADMIN','CUSTCOMBASEINFO_ALL','CUSTCOMBASEINFO_CREATE']"
				class="filter-item"
				size="mini"
				type="primary"
				@click="invalid">失效</el-button>					
      <el-table v-loading="reqLoading" :data="data" size="small" style="width: 100%;" @selection-change="handleSelectionChange">
		    <el-table-column type="selection" width="50"></el-table-column>
		    <el-table-column prop="orderNum" label="序号"/>
			<el-table-column prop="cardCountry" label="证件国别"/>
			<el-table-column prop="cardType" label="证件类型"/>
			<el-table-column prop="cardNum" label="证件编号"/>
			<!-- <el-table-column prop="parseTime(cardEndDate)" label="证件到期日期"/> -->
			<el-table-column prop="cardEndDate" label="证件到期日期">
				<template slot-scope="scope">
				<span>{{ parseTime(scope.row.cardEndDate) }}</span>
				</template>
			</el-table-column>
			<el-table-column prop="cardStatus" label="证件状态"/>
			<el-table-column prop="cardPublishCity" label="证件发布城市"/>
			<el-table-column prop="isMainCard" label="是否主证件"/>
	 </el-table>
	<el-pagination
      :total="total"
      :current-page="page + 1"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>

	  <el-dialog :append-to-body="true" :close-on-click-modal="false" :before-close="cancelAdd" :visible.sync="dialog" title='新增'  width="650px">
		     <el-form ref="forms" :model="addForm" :rules="addRules" size="small" label-width="150px">
				    <el-form-item label="证件国别" prop="cardCountry">
						<el-input v-model="addForm.cardCountry" style="width: 370px;"/>
					</el-form-item>
					<el-form-item label="证件类型" prop="cardType">
						<el-input v-model="addForm.cardType" style="width: 370px;"/>
					</el-form-item>
					<el-form-item label="证件编号" prop="cardNum">
						<el-input v-model="addForm.cardNum" style="width: 370px;"/>
					</el-form-item>
					<el-form-item label="证件到期日期" prop="cardEndDate">
						<!-- <el-input v-model="addForm.cardEndDate" style="width: 370px;"/> -->
						<el-date-picker  type="date" placeholder="选择日期" v-model="addForm.cardEndDate" style="width: 370px;"  value-format="timestamp"></el-date-picker>
					</el-form-item>
					 <!-- <el-form-item label="成立时间" style="display:inline-block;width:48%;">
			<el-form-item prop="date1">
					<el-date-picker  type="date" placeholder="选择日期" v-model="form.foundTime" style="width: 370px;"  value-format="timestamp"></el-date-picker>
			</el-form-item>			
	  </el-form-item> -->
					<el-form-item label="证件状态" prop="cardStatus"> 
						<el-input v-model="addForm.cardStatus" style="width: 370px;"/>
					</el-form-item>
					<el-form-item label="证件发布城市" prop="cardPublishCity">
						<el-input v-model="addForm.cardPublishCity" style="width: 370px;"/>
					</el-form-item>
					<el-form-item label="是否主证件" prop="isMainCard">
						<el-input v-model="addForm.isMainCard" style="width: 370px;"/>
					</el-form-item>
			 </el-form>
			 <div slot="footer" class="dialog-footer">
				<el-button type="text" @click="cancelAdd">取消</el-button>
				<el-button :loading="loading" type="primary" @click="addCredentials">确认</el-button>
			</div>
	  </el-dialog>
  </div>
</template>

<script>
import { get, update } from '@/api/alipay'
import { general,list,credentials,addCredentials,effective} from '@/api/custComBaseinfo'
import initData from '@/mixins/initData'
import { parseTime } from '@/utils/index'
import checkPermission from '@/utils/permission'
export default {
  name: 'Config',
  mixins: [initData],
  data() {
    return {
	  dialog:false,
	  loading: false,
	  addLoading:false,
	  id:'',
      form: { 
		  custNum:'',
           branch:'',
           subBranch:'',
		   deptCode:'',
		   accountManagerName:'',
		   industrialAdjustType:'',
		   customerScaleIn:'',
		   isRegistOverCounty:'',
		   industryKind:'',
		   industryBigKind:'',
		   industryMidKind:'',
		   industrySmallKind:'',
		   jobPeopleNum:'',
		   businessIncome:'',
		   businessSale:'',
		   ledgerStatus:'',
		   realBusinessAddr:'',
		   province:'',
		   preLevelCity:'',
		   riskLevel:'',
		   foundDate:'',
		   isExportType:'',
		   isImportType:'',
		   legalRepresent:'',
		   realController:'',
		   custBankRelationship:'',
		   buildCreditTime:'',
		   isLeadingEnterprise:'',
		   isSupportEnergySaveEnterprise:'',


		// 	appID: '', 
		// 	sysServiceProviderId: '', 
		// 	privateKey: '', 
		// 	publicKey: '',
		//    returnUrl: '', 
		//    notifyUrl: '' 
		 },
		  reqForm:{
			page: 0, 
			size: 10,
			sort:'id,desc',
			id:''
		},
		reqLoading:true,
		reqId:'',
		reqIds:[],
	    addForm:{
		   cardCountry:'',
		   cardType:'',
		   cardNum:'',
		   cardEndDate:'',
		   cardStatus:'',
		   cardPublishCity:'',
		   isMainCard:''
		},
		addRules: {
				cardCountry: [
				  { required: true, message: '请输入证件国别', trigger: 'blur' }
				],
				cardType: [
				  { required: true, message: '请输入证件类型', trigger: 'blur' }
				],
				cardNum: [
				  { required: true, message: '请输入证件编号', trigger: 'blur' }
				],
				cardEndDate: [
				  { required: true, message: '请输入证件到期日期', trigger: 'blur' }
				],
				cardStatus: [
				  { required: true, message: '请输入证件状态', trigger: 'blur' }
				],
				cardPublishCity: [
				  { required: true, message: '请输入证件发布城市', trigger: 'blur' }
				],
		        isMainCard: [
				  { required: true, message: '请输入是否主证件', trigger: 'blur' }
				]

		},

		effectiveParams:{
		   id:'',
		   cardStatus:''
		},
      rules: {
        appID: [
          { required: true, message: '请输入appID', trigger: 'blur' }
        ],
        sysServiceProviderId: [
          { required: true, message: '请输入商家账号', trigger: 'blur' }
        ],
        privateKey: [
          { required: true, message: '商户私钥不能为空', trigger: 'blur' }
        ],
        publicKey: [
          { required: true, message: '支付宝公钥不能为空', trigger: 'blur' }
        ],
        returnUrl: [
          { required: true, message: '回调地址不能为空', trigger: 'blur' }
        ],
        notifyUrl: [
          { required: true, message: '回调地址不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
	  console.log('id----',this.$route.params.id)
	  //this.id = this.$route.params.id
	  
	  console.log('id--------------',this.id)
	  	setTimeout(() => {
				 this.id = sessionStorage.getItem('comCustId')
				 this.reqForm.id = sessionStorage.getItem('comCustId')
				 console.log('this.id',this.id)
				 this.loading = true
				 let that = this
                 general(this.id).then(res => {
					   this.loading = false
					  // that.form = res
					  this.form.custNum = res.custNum
					  this.form.branch = res.branch
					  this.form.subBranch = res.subBranch
                      this.form.deptCode = res.deptCode
					  this.form.accountManagerName = res.accountManagerName
					  this.form.industrialAdjustType = res.industrialAdjustType
					  this.form.customerScaleIn = res.customerScaleIn
                      this.form.isRegistOverCounty = res.isRegistOverCounty
					  this.form.industryKind = res.industryKind
					  this.form.industryBigKind = res.industryBigKind
					  this.form.industryMidKind = res.industryMidKind
					  this.form.industrySmallKind = res.industrySmallKind
					  this.form.jobPeopleNum = res.jobPeopleNum
                      this.form.businessIncome = res.businessIncome
					  this.form.businessSale = res.businessSale
					  this.form.ledgerStatus = res.ledgerStatus
					  this.form.realBusinessAddr = res.realBusinessAddr
					  this.form.province = res.province
					  this.form.preLevelCity = res.preLevelCity
					  this.form.riskLevel = res.riskLevel
					  this.form.foundDate = res.foundDate
					  this.form.isExportType = res.isExportType
					  this.form.isImportType = res.isImportType
					  this.form.legalRepresent = res.legalRepresent
					  this.form.realController = res.realController
					  this.form.custBankRelationship = res.custBankRelationship
					  this.form.buildCreditTime = res.buildCreditTime
					  this.form.isLeadingEnterprise = res.isLeadingEnterprise
					  this.form.isHighTechEnterprise = res.isHighTechEnterprise
					  this.form.isSupportNewTechEnterprise = res.isSupportNewTechEnterprise
					  this.form.isSupportEnergySaveEnterprise = res.isSupportEnergySaveEnterprise

					   console.log('res',res)
                 }).catch(err => {
                       this.loading = false
                       console.log(err.response.data.message)
				}) 
				


                
			   
			    credentials(this.reqForm).then(res => {
					this.total = res.totalElements
					this.data = res.content
					setTimeout(() => {
						this.reqLoading = false
					}, 170)
				}).catch(err => {
					this.reqLoading = false
					console.log(err.response.data.message)
				})






         }, 500)
	  
  },
  methods: {
	   parseTime,
	   checkPermission,
    init() {
	  
        // this.delLoading = true
      general(this.id).then(res => {
        // this.delLoading = false
        // this.$refs[id].doClose()
        // this.dleChangePage()
        // this.init()
        // this.$notify({
        //   title: '删除成功',
        //   type: 'success',
        //   duration: 2500
        // })
      }).catch(err => {
        // this.delLoading = false
        // this.$refs[id].doClose()
        // console.log(err.response.data.message)
      })



    //   get().then(res => {
    //     this.form = res
    //   })
	},
	handleSelectionChange(val) {
		  console.log('val',val)
		   val.forEach((v) => {
               this.reqIds.push(v.id)
		   });
		   console.log('ids',this.reqIds)
		   this.reqId = this.reqIds.toString()
		   this.reqIds = []
	},
	add(){
		this.dialog = true;
	},
	cancelAdd(){
		this.resetForm()
	},
	resetForm() {
      this.dialog = false
	  this.$refs['forms'].resetFields()
	  this.addForm ={
		   cardCountry:'',
		   cardType:'',
		   cardNum:'',
		   cardEndDate:'',
		   cardStatus:'',
		   cardPublishCity:'',
		   isMainCard:''
	  }
	},
	addCredentials(){
		  this.$refs['forms'].validate((valid) => {
				if (valid) {
				this.addLoading = true
				addCredentials(this.addForm).then(res => {
					this.$notify({
					title: '新增成功',
					type: 'success',
					duration: 2500
					})
					this.credentials();
					this.addLoading = false
					this.dialog = false;
				}).catch(err => {
					this.addLoading = false
					console.log(err.response.data.message)
				})
				} else {
				return false
				}
			})
	},
	credentials(){
              credentials(this.reqForm).then(res => {
					this.total = res.totalElements
					this.data = res.content
					setTimeout(() => {
						this.reqLoading = false
					}, 170)
				}).catch(err => {
					this.reqLoading = false
					console.log(err.response.data.message)
				})
	},
	 effective(){
		 this.effectiveParams.id = this.reqId
		 this.effectiveParams.cardStatus = '1' 
		 if(this.effectiveParams.id == ''){
			this.$message.warning('请选择某个复选框') 
			return;
		 }
        effective(this.effectiveParams).then(res => {
            this.$notify({
              title: '已生效',
              type: 'success',
              duration: 2500
			})
			this.credentials();
            // this.loading = false
          }).catch(err => {
            // this.loading = false
            console.log(err.response.data.message)
          })
	 }, 

	 invalid(){
		 this.effectiveParams.id = this.reqId
		 this.effectiveParams.cardStatus = '0' 
		 if(this.effectiveParams.id == ''){
			this.$message.warning('请选择某个复选框') 
			return;
		 }
        effective(this.effectiveParams).then(res => {
            this.$notify({
              title: '已失效',
              type: 'success',
              duration: 2500
			})
			this.credentials();
            // this.loading = false
          }).catch(err => {
            // this.loading = false
            console.log(err.response.data.message)
          })
	 }, 

    doSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true
          update(this.form).then(res => {
            this.$notify({
              title: '修改成功',
              type: 'success',
              duration: 2500
            })
            this.loading = false
          }).catch(err => {
            this.loading = false
            console.log(err.response.data.message)
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped> 
  .head_title{
    height:40px;line-height:40px;border-bottom: 2px solid #ce2731;color:#ce2731
  }
  .space{
	  margin-top:30px;
	  margin-bottom:10px
  }
   .one{
	   display:inline-block;
	   width:86.5%;
   }
   .two{
	   display:inline-block;
	   width:50%;
	
   }


</style>
